<?php
include("include/haut.php");
?>
<div id="corps">
	<h1>Inscription</h1>
	<div id="centre"><?php
	if(isset($_POST['nom']) OR  isset($_POST['prenom']) OR isset($_POST['pseudo']) OR isset($_POST['mail']) OR isset($_POST['j']) OR isset($_POST['m']) OR isset($_POST['a']))
	{
		if(empty($_POST['nom']) OR empty($_POST['prenom']) OR empty($_POST['pseudo']) OR empty($_POST['mail']) OR empty($_POST['j']) OR empty($_POST['m']) OR empty($_POST['a']))
		{
			header('Location: inscription.php?err=1');
		}
		else{
			$pseudo = htmlentities($_POST['pseudo']);
			$nom = htmlentities($_POST['nom']);
			$prenom = htmlentities($_POST['prenom']);
			$email = htmlentities($_POST['mail']);
			$j = htmlentities($_POST['j']);
			$m = htmlentities($_POST['m']);
			$a= htmlentities($_POST['a']);
			$age = mktime(0, 0, 0, $m, $j, $a);
			if(pseudoExiste($pseudo) OR emailExiste($email)){
				header('Location: inscription.php?err=2');
			}
			else
			{
				if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
   				 $user = array();
   				 $user["pseudo"] = $pseudo;
   				 $user["nom"] = $nom;
   				 $user["prenom"] = $prenom;
   				 $user["email"] = $email;
   				 $user["age"] = $age;
   				 $user["password"] = genmdp(6);
   				 envoyerEmailInscription($user);
   				 addUser($user);
   				 ?>
   				 <h2>Inscription terminée !</h2>
   				 <p>Votre inscription s'est correctement déroulée, vous pouvez dès maintenant vous connecter avec les identifiants que vous avez reçu à votre 
   				 	adresse mail</p>

   				 <?php
				}
				else{
					header('Location: inscription.php?err=3');
				} 
			}
		}
	}
	else{
		echo "<h2>Erreur</h2><p>Vous n'avez rien à faire ici.";
	}
		?>
	</div>
</div>
<?php
include("include/bas.php");
?>